﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Model;
using University.Workshop.Business;

namespace University.Workshop.WinApp
{
    public partial class NewPayment : Form
    {
        Payment payment;
        public NewPayment(Payment pPayment)
        {
            InitializeComponent();
            textBoxDate.Text = DateTime.Now.ToShortDateString();
            payment = pPayment;
            LoadDataPatient();
            IssuePermits();
        }

        private void IssuePermits()
        {
            //buttonSave.Enabled = RoleFacade.PermissionUser(Main.userMenu[3], "");
        }

        private void LoadDataPatient()
        {
            textBoxCiPatient.Text = payment.CIPatient;
            textBoxBalance.Text = Convert.ToString(payment.Balance);
            textBoxTotal.Text = Convert.ToString(payment.TotalPayment);
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            payment.CIPatient = textBoxCiPatient.Text;
            payment.DatePayment = textBoxDate.Text;
            payment.Amount = float.Parse(textBoxAmount.Text);
            payment.Balance = float.Parse(textBoxBalance.Text) - float.Parse(textBoxAmount.Text);
            payment.TotalPayment = float.Parse(textBoxTotal.Text);
            payment.Description = textBoxDescription.Text;
            if (PaymentManager.InsertPayment(payment))
            {
                MessageBox.Show("Successful registration");
                this.Close();
            }
            else
            {
                MessageBox.Show("The Payment could not be registered");
            }
        }
    }
}
